package com.eric.service.impl;

import cn.dev33.satoken.util.SaResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eric.domain.dto.EquipmentDTO;
import com.eric.domain.po.Equipment;
import com.eric.mapper.EquipmentMapper;
import com.eric.service.IEquipmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 设备库存表 服务实现类
 * </p>
 *
 * @author eric
 * @since 2024-12-21
 */
@Service
public class EquipmentServiceImpl extends MPJBaseServiceImpl<EquipmentMapper, Equipment> implements IEquipmentService {

    @Override
    public SaResult getAllByPageService(Integer current, Integer pageSize) {
       if (current==null){
           current=1;
       }
       if (pageSize==null||pageSize<=10){
           pageSize=10;
       }

        Page<EquipmentDTO> page=new Page<>(current,pageSize);
       page.setSize(pageSize);
       page.setCurrent(current);
       page.setOptimizeCountSql(false);


       MPJLambdaWrapper<Equipment> wrapper =new MPJLambdaWrapper<Equipment>()
               .selectAll(Equipment.class)
               .eq(Equipment::getDeleted,0)
               .eq(Equipment::getStatus,1)
               .groupBy("create_time")
               .orderByDesc("create_time");

        Page<EquipmentDTO> listPage = selectJoinListPage(page, EquipmentDTO.class, wrapper);
        return SaResult.data(listPage.getRecords()) ;
    }

    @Override
    public SaResult getOneByIdService(Integer id) {

        MPJLambdaWrapper<Equipment>wrapper=new MPJLambdaWrapper<Equipment>()
                .selectAll(Equipment.class)
                .eq(Equipment::getId,id)
                .eq(Equipment::getDeleted,0)
                .eq(Equipment::getStatus,1);
        return SaResult.data(selectJoinOne(EquipmentDTO.class, wrapper))  ;
    }
}
